//
//  DataBase.m
//  VRDemo
//
//  Created by Agensn on 2017/3/9.
//  Copyright © 2017年 🌹Agensn_Master🌹. All rights reserved.
//

#import "DataBase.h"
#import <AFHTTPSessionManager.h>
#import "VRVideo.h"

static DataBase *theData = nil;

@implementation DataBase

+(DataBase *)shareData{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        theData = [[DataBase alloc]init];
    });
    return theData;
}

-(void)jsonData{
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://api.utovr.com/album/get?apptoken=1084962102"]];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        
        
        
        VRVideo *video = [[VRVideo alloc]init];
        
        [video setValuesForKeysWithDictionary:dic];
        
        NSMutableArray *arr = [NSMutableArray array];
        for (NSDictionary *dic in video.data) {
            VRVideoClass *clas = [[VRVideoClass alloc]init];
            [clas setValuesForKeysWithDictionary:dic];
            
            [arr addObject:clas];
        }
        [[NSNotificationCenter defaultCenter]postNotificationName:@"VR" object:arr];
    }];
    [task resume];
}

@end
